package com.aurora.oa.work.adapter;

import android.content.Context;
import android.content.Intent;
import android.net.Uri;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;

import com.aurora.oa.Constants.AuroraConstants;
import com.aurora.oa.R;
import com.aurora.oa.work.bean.AttachmentBean;
import com.aurora.oa.work.bean.WorkLogDataBean;
import com.aurora.oa.work.view.WorkLogDetailActivity;
import com.facebook.drawee.view.SimpleDraweeView;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;

/**
 * Created by Administrator on 2017/4/17 0017.
 */
public class WorkLogAdapter extends BaseAdapter {

    Context context;
    List<WorkLogDataBean> datas;
   public WorkLogAdapter (Context context,List<WorkLogDataBean> datas){
       this.context =context;
       this.datas = datas;
   }
    @Override
    public int getCount() {
        return datas.size();
    }

    @Override
    public WorkLogDataBean getItem(int i) {
        return datas.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(final int i, View view, ViewGroup viewGroup) {
        ViewHolder viewHolder;
        if(view==null){
            view = View.inflate(context,R.layout.item_work_log,null);
            viewHolder =new ViewHolder(view);
            view.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) view.getTag();
        }
        view.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                Intent intent = new Intent(context, WorkLogDetailActivity.class);
                intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
                intent.putExtra("id",datas.get(i).getId());
                context.startActivity(intent);
            }
        });
        viewHolder.tvCompleteProgress.setText(datas.get(i).getSchedule());
        viewHolder.tvCompleteWork.setText(datas.get(i).getCompleted());
       // 1日报2周报3月报4年报
        String logType = "";
        switch (datas.get(i).getType()){
            case 1:
                logType = "日报";
                break;
            case 2:
                logType = "周报";
                break;
            case 3:
                logType = "月报";
                break;
            case 4:
                logType = "年报";
                break;
            default:
                break;

        }
        viewHolder.tvLogtype.setText(logType);
        viewHolder.tvNeedCoordinateWork.setText(datas.get(i).getCoordinated());
        viewHolder.tvRemark.setText(datas.get(i).getRemark());
        viewHolder.tvUncompleteWork.setText(datas.get(i).getUnfinished());
        viewHolder.tv_name.setText(datas.get(i).getUsername());
        viewHolder.tvTime.setText(datas.get(i).getCreatedate());

        viewHolder.sdv_head_img.setImageURI(AuroraConstants.BASE_SERVER_URL+"/"+datas.get(i).getUserHeadImage());
        //把图片地址取出来用
        List<Uri> uriList = new ArrayList<>();
        if(null!=datas.get(i).getAttachments()){
            for(AttachmentBean e:datas.get(i).getAttachments()){
                uriList.add(Uri.parse(AuroraConstants.BASE_SERVER_URL+"/"+e.path));
            }
        }

      //  viewHolder.gvWorkImages.setAdapter(new ImageSeeAdapter(context,uriList));
        return view;
    }

    static class ViewHolder {
        @Bind(R.id.sdv_head_img)
        SimpleDraweeView sdv_head_img;
        @Bind(R.id.tv_title)
        TextView tv_name;
        @Bind(R.id.tv_logtype)
        TextView tvLogtype;
        @Bind(R.id.tv_complete_work)
        TextView tvCompleteWork;
        @Bind(R.id.tv_uncomplete_work)
        TextView tvUncompleteWork;
        @Bind(R.id.tv_need_coordinate_work)
        TextView tvNeedCoordinateWork;
        @Bind(R.id.tv_complete_progress)
        TextView tvCompleteProgress;
        @Bind(R.id.tv_remark)
        TextView tvRemark;
        @Bind(R.id.tv_time)
        TextView tvTime;
/*        @Bind(R.id.gv_work_images)
        GridView gvWorkImages;*/

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
